<template>
  <div class="anytime-service-my-area">
    <c-title text="技能师傅管理"></c-title>
    <van-search v-model="keyword" placeholder="搜索技能师傅名称" shape="round" @search="onSearch"></van-search>
    <van-tabs v-model="active" title-active-color="#4978F8" @click="choose" color="#4978F8">
      <van-tab title="技能师傅" :name="1"></van-tab>
      <van-tab title="待审核" :name="0"></van-tab>
      <van-tab title="审核驳回" :name="-1"></van-tab>
    </van-tabs>

    <div class="box" @click="goto(item)"
       v-for="(item, i) in list" :key="i">
      <div style="display: flex;">
        <img :src="item.personal_pic" />
        <div style="overflow: hidden; display: flex; flex-direction: column;">
          <p class="flex mt11">
            <span class="name">{{ item.realname }}</span>
            <span v-if="item.other1" class="status">已培训</span>
          </p>
          <p class="info">
            <span>{{ item.detail_info.sex }}</span>
            <span class="age">{{ item.detail_info.age }}岁</span>
            <span>{{ item.detail_info.native_place }}</span>
          </p>
          <p class="desc">{{ item.detail_info.introduce }}</p>
          <div class="flex" v-if="active == 1">
            <template v-for="c_item in item.star_grade">
              <van-icon name="star" color="#FF9C43" />
            </template>
          </div>
        </div>
      </div>
      <p class="reason" v-if="active == -1&& item.apply_status==-1">
        <span style="flex-shrink: 0;">驳回原因:</span>
        <span style="text-overflow: ellipsis; overflow: hidden; white-space: nowrap;">{{ item.reason }}</span>
      </p>
    </div>

    <div class="btn" v-if="active == 1 && can_operate" :class="{ 'isPcBtn': fun.isPc() }">
      <van-button block round color="#4978F8" @click="submit">添加技能师傅</van-button>
    </div>
  </div>
</template>

<script>
import { scrollMixin } from "../../../../../utils/mixin";
export default {
  mixins: [scrollMixin],
  data() {
    return {
      keyword: "",
      active: 1,
      isLoadMore: true,
      page: 1,
      last_page: 1,
      list: [],

      can_operate: false
    };
  },
  activated() {
    this.can_operate = false;
    this.getData();
    this.getValidate();
  },
  methods: {
    getValidate() {
      $http.get("plugin.be-within-call.frontend.area-manage.limit", {}, "").then(res => {
        if (res.result) {
          if (res.data.can_operate) {
            this.can_operate = true;
          }
        }
      });
    },
    goto(data) {
      let json = {};
      let apply_for_type = "";
      if (data.apply_status == 0) {//待审核-不可编辑
        apply_for_type = 5;
      } else {
        apply_for_type = 6;
      }
      json.uid = data.has_one_member.uid;
      json.apply_for_type = apply_for_type;
      this.$router.push(this.fun.getUrl("anytimeRoleApply", json));
    },
    choose() {
      this.getData();
    },
    getMoreData() {
      this.isLoadMore = false;
      if (this.page >= this.last_page) {
        return;
      }
      let page = this.page + 1;
      this.getData(page);
    },
    getData(page = 1) {
      let json = {
        state: this.active,
        page
      };
      if (this.keyword) {
        json.name = this.keyword;
      }
      $http.get("plugin.be-within-call.frontend.area-manage.shi-fu-list", json, "").then(res => {
        this.isLoadMore = true;
        if (res.result) {
          let data = res.data;
          this.page = data.current_page;
          this.last_page = data.last_page;
          page == 1 ? (this.list = data.data) : (this.list = this.list.concat(data.data));
          console.log(res.data);
        } else {
          this.$toast(res.msg);
        }
      });
    },
    submit() {
      this.$router.push(this.fun.getUrl("anytimeRoleApply", { apply_for_type: 6 }));
    },
    onSearch() {
      this.getData();
    }
  }
};
</script>

<style scoped lang="scss">

.reason {
  margin-top: 0.5rem;
  text-align: left;
  background: #fff;
  color: #797979;
  display: flex;
  overflow: hidden;
}

.anytime-service-my-area {
  position: relative;
  padding-bottom: 6.25rem;
  min-height: 100vh;

  .isPcBtn {
    width: 375px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
  }

  .btn {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    padding: 0.625rem 0.75rem;
  }

  .box {
    background: #fff;
    margin: 0.5rem 0;
    padding: 0.75rem;
  }

  .status {
    border-radius: 0.125rem;
    border: 1px solid #ff9c43;
    color: #ff9c43;
    font-size: 0.7rem;
    width: 2.625rem;
    height: 1rem;
    line-height: 1rem;
  }

  .info {
    display: flex;
    color: #999;
    font-size: 0.9rem;
    margin-top: 0.3rem;
  }

  .desc {
    overflow: hidden;
    text-overflow: ellipsis;
    color: #999;
    font-size: 0.9rem;
    margin-top: 0.75rem;
    margin-bottom: 0.75rem;
    white-space: nowrap;
    text-align: left;
  }

  .age {
    position: relative;
    padding: 0 0.75rem;

    &::after {
      position: absolute;
      content: "";
      right: 0.375rem;
      bottom: 0;
      height: calc(100% - 20%);
      width: 1px;
      background: #e7e7e7;
    }

    &::before {
      position: absolute;
      content: "";
      left: 0.375rem;
      bottom: 0;
      height: calc(100% - 30%);
      width: 1px;
      background: #e7e7e7;
    }
  }

  .mt11 {
    margin-top: 0.3438rem;
  }

  .flex {
    display: flex;
    align-items: center;
  }

  .name {
    font-size: 0.9rem;
    font-weight: 500;
    color: #333;
    margin-right: 0.25rem;
  }

  img {
    width: 6.8125rem;
    height: 6.8125rem;
    border-radius: 0.25rem 0.25rem 0.25rem 0.25rem;
    margin: 0 0.375rem 0 0;
  }
}
</style>
